package com.example.wilson.lesson13_1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btnStartPlay;
    private Button btnStopPlay;
    private Intent intentPlay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setTitle("520 xxx");

        initView();
    }

    private void initView() {

        btnStartPlay = (Button) findViewById(R.id.btn_start_play);
        btnStopPlay = (Button) findViewById(R.id.btn_stop_play);
        btnStartPlay.setOnClickListener(this);
        btnStopPlay.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_start_play:
                Toast.makeText(MainActivity.this, "绑定了platService", Toast.LENGTH_LONG).show();
                intentPlay = new Intent(MainActivity.this, MusicService.class);
                startService(intentPlay);
                break;
            case R.id.btn_stop_play:
                stopService(intentPlay);
                Toast.makeText(MainActivity.this, "解绑了platService", Toast.LENGTH_LONG).show();
                break;

        }
    }
}
